using System;

namespace FluentParser.Expressions
{
    /// <summary>
    /// The type of error informs how an ErrorExpression/ErrorSymbol will behave when
    /// it is activated.
    /// </summary>
    public enum ParsingExceptionType
    {
        /// <summary> This type of error instantly throws an exception when used. </summary>
        FatalError,

        /// <summary> This type of error has a chance to recover if it is allowed to. </summary>
        Error,

        /// <summary> This type of error will always recover. </summary>
        Warning,
    }

    /// <summary> This is the exception thrown by custom error handling. </summary>
    public class ParsingException : Exception
    {
        public ParsingException(ParsingExceptionType type, string message, int start, int length) : base(message)
        {
            TypeException = type;
            Start = start;
            Length = length;
        }

        /// <summary> The type of the exception which determine its behavior. </summary>
        public ParsingExceptionType TypeException { get; private set; }

        /// <summary> The initial index of parsed text which failed. </summary>
        public int Start { get; private set; }

        /// <summary> The length of the parsed text which failed. </summary>
        public int Length { get; private set; }

        /// <summary> The last character index of parsed text which failed. </summary>
        public int End { get { return Start + Length; } }
    }
}